package com.solidumgame.ninja.pot
{
	import com.pblabs.engine.entity.EntityComponent;
	import com.solidumgame.ninja.pot.events.PotGenericEvents;
	
	import flash.media.Sound;
	import flash.net.URLRequest;

	public class PotSoundComponent extends EntityComponent
	{
			private var sound:Sound;
			private var url:URLRequest;
			
			public function PotSoundComponent()
			{
			}
				
			override protected function onAdd():void{
				super.onAdd();
				owner.eventDispatcher.addEventListener(PotGenericEvents.POT_TRHOW_ENTER,soundTableIn);
				owner.eventDispatcher.addEventListener(PotGenericEvents.POT_TRHOW_EXIT,soundTableOut);
			}
			
			override protected function onRemove():void{
				super.onRemove();
				owner.eventDispatcher.removeEventListener(PotGenericEvents.POT_TRHOW_ENTER,soundTableIn);
				owner.eventDispatcher.removeEventListener(PotGenericEvents.POT_TRHOW_EXIT,soundTableOut);
				
			}
			
			public function soundTableIn(e:PotGenericEvents):void{
				url = new URLRequest("../assets/sounds/WoodInSound.mp3");
				sound = new Sound(url);
				sound.play(0,0);
			}
			
			public function soundTableOut(e:PotGenericEvents):void{
				url = new URLRequest("../assets/sounds/WoodOutSound.mp3");
				sound = new Sound(url);
				sound.play(0,0);
			}
		}
	}